package com.alcj.service.impl;

import com.alcj.mapper.SelfImgMapper;
import com.alcj.mapper.SelfMCategoryMapper;
import com.alcj.mapper.SelfPCategoryMapper;
import com.alcj.mapper.SelfProjectMapper;
import com.alcj.model.SelfImg;
import com.alcj.model.SelfMCategory;
import com.alcj.model.SelfPCategory;
import com.alcj.model.SelfProject;
import com.alcj.service.SelfProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author : LiangZhao
 * @version :v1.0
 * @Package : com.alcj.service.impl
 * @Description :自检项目业务实现类
 * @date : 2017/10/12 19:46
 */
@Service
public class SelfProjectServiceImpl implements SelfProjectService {

    /**
     * 自检结果数据库接口
     */
    @Autowired
    SelfProjectMapper selfProjectMapper;

    /**
     * 自检小分类数据库接口
     */
    @Autowired
    SelfMCategoryMapper selfMCategoryMapper;

    /**
     * 自检大分类数据库接口
     */
    @Autowired
    SelfPCategoryMapper selfPCategoryMapper;

    /**
     * 自检项目图片数据库接口
     */
    @Autowired
    SelfImgMapper selfImgMapper;

    /**
     * @Author: LiangZhao
     * @Description: 获取自检结果
     * @Date: 2017/9/8 10:59
     * @param: record 用户编号
     * @return: 查询结果
     */
    @Override
    public List<SelfProject> getSelfProject(String record) throws Exception {

        return selfProjectMapper.selectByUser(record);
    }

    /**
     * @Author: LiangZhao
     * @Description: 保存自检结果
     * @Date: 2017/9/8 10:59
     * @param: record 自检结果
     * @return: 查询结果
     */
    @Override
    public int addSelfProject(List<SelfProject> record, String userId) throws Exception {

        //删除该用户的所有自检信息
        selfProjectMapper.deleteByUserId(userId);
        //保存当前的自检结果
        return selfProjectMapper.insertBatch(record);
    }

    @Override
    public int editSelfProject(List<SelfProject> record) throws Exception {
        return 0;
    }

    @Override
    public int delSelfProject(String record) throws Exception {
        return 0;
    }

    /**
     * @Author: LiangZhao
     * @Description: 获取全部自检大分类
     * @Date: 2017/9/8 10:59
     * @return: 查询结果
     */
    @Override
    public List<SelfPCategory> getSelfPCategory() throws Exception {
        return selfPCategoryMapper.getSelfPCategoryAll();
    }

    /**
     * @Author: LiangZhao
     * @Description: 获取全部自检小分类
     * @Date: 2017/9/8 10:59
     * @param: record 大分类编号
     * @return: 查询结果
     */
    @Override
    public List<SelfMCategory> getSelfMCategory(SelfMCategory record) throws Exception {
        return selfMCategoryMapper.getSelfMCategoryByPC(record);
    }

    /**
     * @Author: LiangZhao
     * @Description: 获取自检项目图片
     * @Date: 2017/9/8 10:59
     * @param: record 自检项目编号
     * @return: 查询结果
     */
    @Override
    public List<SelfImg> getSelfImg(int record) throws Exception {
        return selfImgMapper.selectBySprId(record);
    }
}
